#!/usr/bin/python
import os, pygame

class BoardUnit:
    def __init__(self):
        self.left = True
        self.right = True
        self.up = True
        self.down = True
        self.upleft = False
        self.upright = False
        self.downleft = False
        self.downright = False
        self.chesses = []
        
class ChessBoard:

    def __init__(self):
        #self.NoneUnit = pygame.sprite.Sprite()
        self.box = [[BoardUnit() for x in range(13)] for y in range(13)]
        self._init_boardunit()
        #self._set_chessposition()
        
    def _init_boardunit(self):
        for i in range(2, 11):
            self.box[1][i].left = False
            self.box[11][i].right = False
            self.box[i][1].up = False
            self.box[i][11].down = False
        self.box[2][1].left = False
        self.box[2][1].downleft = True
        self.box[1][2].up = False
        self.box[1][2].upright = True
        
        self.box[10][1].right = False
        self.box[10][1].downright = True
        self.box[11][2].up = False
        self.box[11][2].upleft = True
        
        self.box[2][11].left = False
        self.box[2][11].upleft = True
        self.box[1][10].down = False
        self.box[1][10].downright = True
        
        self.box[10][11].right = False
        self.box[10][11].upright = True
        self.box[11][10].down = False
        self.box[11][10].downleft = True
        
        self.box[5][1].downright = True
        self.box[7][1].downleft = True
        self.box[6][2].upleft = True
        self.box[6][2].upright = True
        
        self.box[1][5].downright = True
        self.box[1][7].upright = True
        self.box[2][6].upleft = True
        self.box[2][6].downleft = True

        self.box[11][5].downleft = True
        self.box[11][7].upleft = True
        self.box[10][6].upright = True
        self.box[10][6].downright = True

        self.box[5][11].upright = True
        self.box[7][11].upleft = True
        self.box[6][10].downleft = True
        self.box[6][10].downright = True

        self.box[5][5].downright = True
        self.box[7][5].downleft = True
        self.box[5][7].upright = True
        self.box[7][7].upleft = True
        self.box[6][6].upleft = True
        self.box[6][6].upright = True
        self.box[6][6].downleft = True
        self.box[6][6].downright = True
        
    def append_chess(self, chess, x, y):
        self.box[x][y].chesses.append(chess)
        
    def remove_chess(self, chess, x, y):
        self.box[x][y].chesses.remove(chess)

    def chesslist(self, x, y):
        return self.box[x][y].chesses

    def boardcell(self, x, y):
        return self.box[x][y]

if __name__ == "__main__":
    test = ChessBoard()

